package com.mobile.sync.client.impl;

import java.io.UnsupportedEncodingException;
import java.util.Set;

public class RequestBean extends AbstractBean {
	private String authUri;
	private RequestMethod httpMethod;

	public enum RequestMethod {
		HttpPost
	}

	public RequestBean(String authUri, RequestMethod httpMethod) {
		this.authUri = authUri;
		this.httpMethod = httpMethod;
	}

	public String getAuthUri() {
		return authUri;
	}

	public void setAuthUri(String authUri) {
		this.authUri = authUri;
	}

	public RequestMethod getHttpMethod() {
		return httpMethod;
	}

	public void setHttpMethod(RequestMethod httpMethod) {
		this.httpMethod = httpMethod;
	}

	public String getRequestBodyAsUtfString() {
		if (null != dataChunk) {
			try {
				return new String(dataChunk, "UTF-8");
			} catch (UnsupportedEncodingException ex) {
				ex.printStackTrace();
				return "";
			}
		}
		return "";
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("[Response from : " + this.authUri + "]");
		Set<String> headerNames = headers.keySet();
		for (String headerKey : headerNames) {
			String headerVal = headers.get(headerKey);
			builder.append("[" + headerKey + ": " + headerVal + "]");
			builder.append("\r\n");
		}
		return builder.toString();
	}

}
